using System;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;

namespace cmd
{
    [Serializable]
    public readonly struct PickableItemDataOverride
    {
        #region 构造函数
        public PickableItemDataOverride(
            bool isOverrideQuality = false,
            IntRange? qualityOverride = null,
            bool isOverrideName = false,
            string nameOverride = "",
            bool isOverrideBaseWeight = false,
            FloatRange? baseWeightOverride = null,
            bool isOverrideVolume = false,
            FloatRange? volumeOverride = null,
            bool isOverrideMoveSpeed = false,
            FloatRange? moveSpeedOverride = null,
            bool isOverrideSpawnRange = false,
            FloatRange? spawnRangeOverride = null,
            bool isOverrideUnityValue = false,
            FloatRange? unitValueOverride = null
        )
        {
            IsOverrideQuality = isOverrideQuality;
            QualityOverride =
                qualityOverride == null
                    ? IntRange.CreateWithLimitation(1, 3)
                    : qualityOverride.Value;
            IsOverrideName = isOverrideName;
            NameOverride = nameOverride;
            IsOverrideBaseWeight = isOverrideBaseWeight;
            BaseWeightOverride =
                baseWeightOverride == null
                    ? FloatRange.CreateWithLimitation(0, 100)
                    : baseWeightOverride.Value;
            IsOverrideVolume = isOverrideVolume;
            VolumeOverride =
                volumeOverride == null
                    ? FloatRange.CreateWithLimitation(50, 150)
                    : volumeOverride.Value;
            IsOverrideMoveSpeed = isOverrideMoveSpeed;
            MoveSpeedOverride =
                moveSpeedOverride == null
                    ? FloatRange.CreateWithLimitation(0, 10)
                    : moveSpeedOverride.Value;
            IsOverrideSpawnRange = isOverrideSpawnRange;
            SpawnRangeOverride =
                spawnRangeOverride == null
                    ? FloatRange.CreateWithLimitation(0, 100)
                    : spawnRangeOverride.Value;
            IsOverrideUnitValue = isOverrideUnityValue;
            UnitValueOverride =
                unitValueOverride == null
                    ? FloatRange.CreateWithLimitation(0, 100)
                    : unitValueOverride.Value;
        }

        #endregion

        #region 属性
        [OdinSerialize, ToggleGroup(nameof(IsOverrideQuality))]
        [LabelText("是否启用品质覆盖")]
        public bool IsOverrideQuality { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideQuality))]
        [field: LabelText("品质覆盖")]
        [field: Tooltip("如果启用就覆盖原始的中的品质")]
        public IntRange QualityOverride { get; init; }

        [OdinSerialize, ToggleGroup(nameof(IsOverrideName))]
        [LabelText("是否启用名字覆盖")]
        public bool IsOverrideName { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideName))]
        [field: LabelText("名字覆盖")]
        [field: Tooltip("如果启用就覆盖原始的中的名字")]
        public string NameOverride { get; init; }

        [OdinSerialize, ToggleGroup(nameof(IsOverrideBaseWeight))]
        [LabelText("是否启用基础重量覆盖")]
        public bool IsOverrideBaseWeight { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideBaseWeight))]
        [field: LabelText("基础重量覆盖")]
        [field: Tooltip("如果启用就覆盖原始的中的基础重量")]
        public FloatRange BaseWeightOverride { get; init; }

        [OdinSerialize, ToggleGroup(nameof(IsOverrideVolume))]
        [LabelText("是否启用体积覆盖")]
        public bool IsOverrideVolume { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideVolume))]
        [field: LabelText("体积覆盖")]
        [field: Tooltip("如果启用就覆盖原始的中的体积")]
        public FloatRange VolumeOverride { get; init; }

        [OdinSerialize, ToggleGroup(nameof(IsOverrideMoveSpeed))]
        [LabelText("是否启用移动速度覆盖")]
        public bool IsOverrideMoveSpeed { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideMoveSpeed))]
        [field: LabelText("移动速度覆盖")]
        [field: Tooltip("如果启用就覆盖原始的中的移动速度")]
        public FloatRange MoveSpeedOverride { get; init; }

        [OdinSerialize, ToggleGroup(nameof(IsOverrideSpawnRange))]
        [LabelText("是否启用生成高度覆盖")]
        public bool IsOverrideSpawnRange { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideSpawnRange))]
        [field: LabelText("生成高度覆盖")]
        [field: Tooltip("如果启用就覆盖原始的中的生成高度")]
        public FloatRange SpawnRangeOverride { get; init; }

        [OdinSerialize, ToggleGroup(nameof(IsOverrideUnitValue))]
        [LabelText("是否启用单位价值覆盖")]
        public bool IsOverrideUnitValue { get; init; }

        [field: SerializeField, ToggleGroup(nameof(IsOverrideUnitValue))]
        [field: LabelText("单位价值覆盖")]
        [field: Tooltip("如果启用就覆盖原始的单位价值")]
        public FloatRange UnitValueOverride { get; init; }

        #endregion
    }
}
